package thirdPartyUtils;

import net.coobird.thumbnailator.Thumbnails;

import java.io.File;
import java.io.IOException;

public class thumbnails {
    public static void main(String[] args) throws IOException {
        String prefix = "D:\\Thumbnails\\";
        String filepath=prefix + "1.jpg";
        File fromFile = new File(filepath);
        // 修改像素，这里指定改为100px*100px的图片
        Thumbnails.of(fromFile).size(100, 100).toFile(prefix + "100100.jpg");
        // 按比例缩小，0.5f就是四分之一大小
        Thumbnails.of(fromFile).scale(0.5f).toFile(prefix + "05f.jpg");
//        Thumbnails.of(fromFile).scale(1f).toFile(prefix + "1f.jpg");
        Thumbnails.of(fromFile).scale(1f).toFile(prefix + "1f.png");
        Thumbnails.of(fromFile).scale(2f).toFile(prefix + "2f.jpg");
        // 尺寸不变，通过输出质量修改文件大小，大小不可控
        Thumbnails.of(fromFile).scale(1).outputQuality(0.002f).toFile(prefix + "lowQuality.jpg");
    }
}
